<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>父子组件传值</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="app">
    <input type="text" v-model="inputValue">
    <button @click="handleBtnClick">提交</button>
    <ul>
      <!-- <li v-for="item in list">{{item}}</li> -->
      <todo-item v-for="(item,index) in list"
                 v-bind:content="item"
                 @delete="handleItemDelete"
                 v-bind:index="index">     
      </todo-item>
    </ul>
    
  </div>
  <script>
    var TodoItem = {
      props:['content', 'index'],
      template: "<li @click='handleItemClick'>{{content}}</li>",
      methods: {
        handleItemClick: function() {
          // alert("delete");
          this.$emit("delete", this.index);
        }
      }
    }
    var page = new Vue({
      el: '#app',
      components: {
        TodoItem: TodoItem
      },
      data: {
        list: [],
        inputValue: ''
      },
      methods: {
        handleBtnClick: function() {
          this.list.push(this.inputValue);
          this.inputValue= '';
        },
        handleItemDelete: function (index) {
          // alert(index);
          this.list.splice(index, 1);
        }
      }
    })
  </script>
</body>
</html>